package javacode.chapter07;

import java.util.concurrent.ExecutionException;

public class Example7_5 {
    public static void main(String[] args) {
        Student student = new Student("小明");
        try {
            student.setScore(110);
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }
}

class Student{
    private String name;// 姓名
    private int score;// 成绩

    public Student(String name) {
        this.name=name;
    }

    public void setScore(int score) throws Exception{
        if (score>=0&&score<=100){
            this.score=score;
        }else{
            throw new Exception("成绩必须在0到100之间!");
        }
    }
}
